home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_066 / nart / nart.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  179 lines

  1. /*  :ts=8 bk=0
  2.  * In the tradition of stupid programs, Leo Schwab presents (yet again)
  3.  * The Art Program.
  4.  *
  5.  * Modofied to do even neater things.
  6.  * 8607.1
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <graphics/gfxbase.h>
  11. #include <intuition/intuition.h>
  12.  
  13. #define XSIZE           319
  14. #define YSIZE           199
  15.  
  16. extern int rnd();
  17.  
  18. struct IntuitionBase    *IntuitionBase;
  19. struct GfxBase          *GfxBase;
  20. struct Screen   *scr, *OpenScreen();
  21. struct Window   *win, *OpenWindow();
  22. struct ViewPort *vp;
  23.  
  24. struct NewScreen scrdef = {
  25.         0, 0, XSIZE+1, YSIZE+1,
  26.         4,              /*  16 colors  */
  27.         0, 1,           /*  detail/block pens  */
  28.                         /*  "Automatically" set up screen format  */
  29.         ((XSIZE>320) ? HIRES : 0) | ((YSIZE>200) ? LACE : 0),
  30.         CUSTOMSCREEN,
  31.         NULL, NULL, NULL, NULL  /* no special font, title, gadg, or bitmap */
  32. };
  33.  
  34. struct NewWindow windef = {
  35.         0, 0, XSIZE+1, YSIZE+1,
  36.         0, 1,
  37.         CLOSEWINDOW,
  38.         WINDOWCLOSE | BACKDROP | BORDERLESS,
  39.         NULL, NULL, NULL,       /* no special gadget, checkmark or title */
  40.         NULL,                   /* screen pointer; will get set later */
  41.         NULL,                   /* no custom bitmap */
  42.         0, 0, 0, 0,             /* ignored */
  43.         CUSTOMSCREEN
  44. };
  45.  
  46. main ()
  47. {
  48.         register struct RastPort *rp;
  49.         int i, dx1, dy1, dx2, dy2, pen = 16, flag = 0,
  50.             xa1[150], ya1[150], xa2[150], ya2[150];
  51.         register int x1, y1, x2, y2;
  52.  
  53.         openstuff ();
  54.         rnd (-87634);
  55. /*    rp = win -> RPort;    <-- This is slower because of layers    */
  56.         rp = & (scr -> RastPort);
  57.         SetDrMd (rp, COMPLEMENT);
  58.         ShowTitle (scr, FALSE);
  59.         SetRast (rp, 0);
  60.         x1 = rnd (XSIZE+1);  y1 = rnd (YSIZE+1);
  61.         x2 = rnd (XSIZE+1);  y2 = rnd (YSIZE+1);
  62.         setdisp (&dx1, &dy1);
  63.         setdisp (&dx2, &dy2);
  64.  
  65.        while (1) {
  66.         for (i=0; i<150; i++) {
  67.         rotate ();
  68.                 if (GetMsg (win -> UserPort)) {
  69.                         closestuff ();
  70.                         exit (TRUE);
  71.                 }
  72.                 if (rnd (12) == 3)
  73.                         if (rnd (2))
  74.                                 setdisp (&dx1, &dy1);
  75.                         else
  76.                                 setdisp (&dx2, &dy2);
  77.  
  78.                 x1 += dx1;  y1 += dy1;
  79.                 if (x1 > XSIZE || x1 < 0) {
  80.                         dx1 = -dx1;
  81.                         x1 = x1<0 ? 0 : XSIZE;
  82.                 }
  83.                 if (y1 > YSIZE || y1 < 0) {
  84.                         dy1 = -dy1;
  85.                         y1 = y1<0 ? 0 : YSIZE;
  86.                 }
  87.                 x2 += dx2;  y2 += dy2;
  88.                 if (x2 > XSIZE || x2 < 0) {
  89.                         dx2 = -dx2;
  90.                         x2 = x2<0 ? 0 : XSIZE;
  91.                 }
  92.                 if (y2 > YSIZE || y2 < 0) {
  93.                         dy2 = -dy2;
  94.                         y2 = y2<0 ? 0 : YSIZE;
  95.                 }
  96.  
  97.                 if (!--pen)
  98.                         pen = 15;
  99.                 rp -> Mask = pen;       /* kludge; COMPLEMENT does not  */
  100.                 Move (rp, x1, y1);      /* perform as advertised  */
  101.                 Draw (rp, x2, y2);
  102.                 if (flag) {
  103.                         Move (rp, xa1[i], ya1[i]);
  104.                         Draw (rp, xa2[i], ya2[i]);
  105.                 }
  106.                 xa1[i] = x1;  ya1[i] = y1;
  107.                 xa2[i] = x2;  ya2[i] = y2;
  108.         }
  109.        flag = 1;
  110.        }        /* End of the while */
  111. }
  112.  
  113. openstuff ()
  114. {
  115.         if (!(IntuitionBase = (struct IntuitionBase *)
  116.             OpenLibrary ("intuition.library", 1))) {
  117.                 printf ("Awright, where's Intuition?\n");
  118.                 exit (FALSE);
  119.         }
  120.  
  121.         if (!(GfxBase = (struct GfxBase *)
  122.             OpenLibrary ("graphics.library", 1))) {
  123.                 printf ("Graphics?  Heeeere graphics....\n");
  124.                 exit (FALSE);
  125.         }
  126.  
  127.     if (!(scr = OpenScreen (&scrdef))) {
  128.                 printf ("Can't open your screen.\n");
  129.                 exit (FALSE);
  130.         }
  131.  
  132.         windef.Screen = scr;
  133.         if (!(win = OpenWindow (&windef))) {
  134.                 printf ("Window painted shut.\n");
  135.                 exit (FALSE);
  136.         }
  137.     vp = &(scr -> ViewPort);
  138.     setcolors ();
  139. }
  140.  
  141. closestuff ()
  142. {
  143.         CloseWindow (win);
  144.         CloseScreen (scr);
  145.         CloseLibrary (GfxBase);
  146.         CloseLibrary (IntuitionBase);
  147. }
  148.  
  149. setdisp (x, y)
  150. register int *x, *y;
  151. {
  152.         *x = rnd (9) - 4;
  153.         *y = rnd (9) - 4;
  154. }
  155.  
  156. /*  What I really wanted was the HSL color wheel.  Oh well....  */
  157. setcolors ()
  158. {
  159.     int r, g, b, i;
  160.  
  161.     for (i=1; i<16; i++) {
  162.         if (i <= 5) {
  163.             r = (6-i) * 15 / 5;
  164.             g = (i-1) * 15 / 5;
  165.             b = 0;
  166.         } else if (i > 5 && i <= 10) {
  167.             r = 0;
  168.             g = (11-i) * 15 / 5;
  169.             b = (i-5) * 15 / 5;
  170.         } else if (i > 10) {
  171.             r = (i-10) * 15 / 5;
  172.             g = 0;
  173.             b = (16-i) * 15 / 5;
  174.         }
  175.         SetRGB4 (vp, i, r, g, b);
  176.     }
  177.     SetRGB4 (vp, 0, 0, 0, 0);
  178. }
  179.